<template>
	<view class="nameEdit">
		<topNav rightText="完成" @rightBtn="editName">
			<template slot="middle">
				<view>昵称</view>
			</template>
		</topNav>
		<input maxlength="10" placeholder-class="placeStyle" class="userName" v-model.trim ="userName" placeholder="请输入您的昵称" type="text" auto-focus="true" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userName:''
			};
		},
		onShow() {
			this.getUserInfos();
		},
		methods:{
			getUserInfos(){
				let userInfo = uni.getStorageSync('userInfo');
				if(userInfo && userInfo != ''){
					this.userName = userInfo.userName;
				}
			},
			async editName(){
				const _this = this;
				if(_this.userName == ''){
					return _this.$showToast('昵称不能为空哦～')
				};
				let res = (await _this.$http('/api/auth/user/updateUserInfo',"POST",{
					userName:_this.userName
				})).data;
				if(res && res.code == '0'){
					_this.$showToast(res.msg);
					setTimeout(()=>{
						_this.$navBack();
					},1000)
				}else{
					_this.$showToast(res.msg);
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.nameEdit{
		width: 100%;
		min-height: 100vh;
		background-color: #F6F6F6;
		.userName{
			box-sizing: border-box;
			width: 100%;
			height: 104rpx;
			background-color: #fff;
			margin-top: 20rpx;
			color: #000;
			padding: 32rpx 24rpx;
		}
	}
</style>
